﻿:: ============================
:: 注意: 更新此文件后，请在UpdateHistory.txt做备注，否则不会触发该脚本。
:: ============================
 
::echo %cd%
::echo %~dp0

cd %~dp0

rem @echo off

set ROOTDIR=..\..\
set OUTDIR=%~1
set CONFIG=%~2
set PLATFORM=%~3
echo "%OUTDIR%"
::pause

:: GCMK_SDK
call :copydirectory "%ROOTDIR%ThirdParty\GCMP_SDK\bin\%CONFIG%\*.*" "%OUTDIR%"

:: gbmp_category_and_style_config
call :copyfile "%ROOTDIR%data\gbmp_category_and_style_config\*.*" "%OUTDIR%\gbmp_category_and_style_config\"

call :delete_folders_and_files "%OUTDIR%gbmp_plugin_config"
md "%OUTDIR%gbmp_plugin_config"
call :copydirectory "%ROOTDIR%data\gbmp_plugin_config" "%OUTDIR%gbmp_plugin_config"

call :delete_folders_and_files "%OUTDIR%SampleData"
md "%OUTDIR%SampleData"
call :copydirectory "%ROOTDIR%data\SampleData" "%OUTDIR%SampleData"

:: journal_config
call :copyfile "%ROOTDIR%data\journal_config.json" "%OUTDIR%\"

goto done
:: ========================================================

:: ========================================================
:done
:: ========================================================

:: UpdateHistory.txt (Don't remove)
call :copyfile UpdateHistory.txt  "%OUTDIR%"
goto:eof

:: Delete all files and folders/subfoldrs.
:: Usage: Require top folder name as the only argument 
:delete_folders_and_files
del /q /s %~1
IF %ERRORLEVEL% GTR 0 (
    echo 不能删除 %~1 里的文件
    exit %ERRORLEVEL%)
rd /q /s %~1
IF %ERRORLEVEL% GTR 0 (
    echo 不能删除 %~1 或里面的文件夹
    exit %ERRORLEVEL%)
goto:eof

:copyfile 
xcopy /y /f %~1 %~2
IF %ERRORLEVEL% GTR 0 (
    echo 不能拷贝 %~1 到 %~2
    exit %ERRORLEVEL%)
goto:eof

:copydirectory
xcopy /e /y %~1 %~2
IF %ERRORLEVEL% GTR 0 (
    echo 不能拷贝 %~1 到 %~2
    exit %ERRORLEVEL%)
goto:eof

